import { _decorator, Component, director } from 'cc';
import GGameManager from '../src-game/manager/game.game.manager';
import { ClientAPI } from './api/client.api';
import GameManager from './manager/game.manager';
const { ccclass, property } = _decorator;

@ccclass('LoadScene')
export class LoadScene extends Component {

	private load_scene: Promise<string>;

	protected onLoad(){
		this.load_scene = ClientAPI.GameType()
		.then(type=>type.type == 'A' ? 'demo' : 'official');
	}

	start() {
		mtec.cc.adaptBackgroundNode(this.node);
		this.load_scene.then(scene=>{
			if(scene == 'official'){
				GameManager.init().then(()=>{
					if(!mtec.local.read(GameManager.AppName + 'GameInitFinish')){
						GameManager.userPoint('GameInitStart');
					}
					director.loadScene(scene);
				});
			}else{
				GGameManager.init().then(()=>{
					director.loadScene(scene);
				});
			}
		});
	}
}
